package com.example.javademo.Controller;

import com.example.javademo.Entity.User;
import com.example.javademo.Service.UserAuthService;
import com.example.javademo.Utils.Response;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@RestController
@RequestMapping("/api/auth")
@Tag(name = "用户认证接口", description = "用户注册和认证相关的API")
public class UserAuthController {
    private static final Logger log = LoggerFactory.getLogger(UserAuthController.class);
    @Autowired
    private UserAuthService userAuthService;
    @PostMapping("/regist")
    @Operation(
            summary = "用户注册",
            description = "用于用户注册的新接口",
            parameters = {
                    @Parameter(name = "userRequest", description = "用户注册请求体", required = true, schema = @Schema(implementation = User.class))
            },
            responses = {
                    @ApiResponse(
                            responseCode = "200",
                            description = "注册成功",
                            content = @Content(schema = @Schema(implementation = Response.class))
                    ),
            }
    )

    public Response register(@RequestBody User userRequest){
//        TODO:注册接口
//          List<User> userList =userAuthService.register();
            System.out.println(userRequest+"111111");
            log.info("用户详细信息: {}", userRequest);
           return  userAuthService.register(userRequest);
    }
    @PostMapping("/login")
    @Operation(
            summary = "用户登录",
            description = "用于用户登录的新接口",
            parameters = {
                    @Parameter(name = "userRequest", description = "用户登录请求体", required = true, schema = @Schema(implementation = User.class))
            },
            responses = {
                    @ApiResponse(
                            responseCode = "200",
                            description = "登录成功",
                            content = @Content(schema = @Schema(implementation = Response.class))
                    ),
            }
    )
    public Response login(@RequestBody User userRequest){
//        TODO:登录接口
        return  userAuthService.login(userRequest);
    }

}
